using Sinacor.Infra.UI.Common;
using System.Collections.Generic;
using Sinacor.UI.Bovespa.Parametro.Communication.Bovespa.Parametro.ParametroBolsa;
using Sinacor.Infra.UI.Security.Services;
using System;

namespace Sinacor.UI.Bovespa.Parametro.Communication
{
    public class ParametroBolsa : BaseCommunication
    {

        public ParametroBolsa(SessionInformation session)
            : base(session) { }

		public void AlterarParametroBolsa(Model.ParametroBolsa model)
        {
            IParametroBolsa servico = null;

            ModelCollection<Sinacor.UI.Bovespa.Parametro.Model.ParametroBolsa> response = null;

            try
            {
                using (ServiceInstance<IParametroBolsa> service = new ServiceInstance<IParametroBolsa>())
                {
                    servico = service.TryGetInstance(this.Session);
                    servico.AlterarParametroBolsa(new Communication.Translator.ModelToDataContract.ParametroBolsa().ToParametroBolsaRequest(model));
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }
		}

		public void AlterarTipoNota(Model.TipoNota parameter)
        {
            IParametroBolsa servico = null;

            ModelCollection<Sinacor.UI.Bovespa.Parametro.Model.ParametroBolsa> response = null;

            try
            {
                using (ServiceInstance<IParametroBolsa> service = new ServiceInstance<IParametroBolsa>())
                {
                    servico = service.TryGetInstance(this.Session);
                    servico.AlterarTipoNota(new Communication.Translator.ModelToDataContract.ParametroBolsa().ToTipoNotaRequest(parameter));
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }
		}

		public void AtualizarParametroBolsa(Model.ParametroBolsa parametroBolsaRequest, ModelCollection<Model.TipoNota> tiposNotasList)
        {
            IParametroBolsa servico = null;

            ModelCollection<Sinacor.UI.Bovespa.Parametro.Model.ParametroBolsa> response = null;

            try
            {
                using (ServiceInstance<IParametroBolsa> service = new ServiceInstance<IParametroBolsa>())
                {
                    servico = service.TryGetInstance(this.Session);
                    servico.AtualizarParametroBolsa(new Communication.Translator.ModelToDataContract.ParametroBolsa().ToParametroBolsaRequest(parametroBolsaRequest), new Communication.Translator.ModelToDataContract.ParametroBolsa().ToTipoNotaRequest(tiposNotasList));
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }
		}

		public ModelCollection<Model.TipoNota> ConsultarTiposNotas(Model.Parameter.FiltroTipoNota parameter)
        {
            IParametroBolsa servico = null;

            ModelCollection<Sinacor.UI.Bovespa.Parametro.Model.TipoNota> response = null;

            try
            {
                using (ServiceInstance<IParametroBolsa> service = new ServiceInstance<IParametroBolsa>())
                {
                    servico = service.TryGetInstance(this.Session);
                    response = (new Communication.Translator.DataContractToModel.ParametroBolsa().ToTipoNota(servico.ConsultarTiposNotas(new Communication.Translator.ModelToDataContract.ParametroBolsa().ToFiltroTipoNotaRequest(parameter))));
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }

            return response;
		}

		public Model.ParametroBolsa ObterParametroBolsa()
        {

            IParametroBolsa servico = null;

            Model.ParametroBolsa retorno = null;

            try
            {
                using (ServiceInstance<IParametroBolsa> service = new ServiceInstance<IParametroBolsa>())
                {
                    servico = service.TryGetInstance(this.Session);

                    Communication.Translator.DataContractToModel.ParametroBolsa _translatorDataContractToModel = new Communication.Translator.DataContractToModel.ParametroBolsa();

                    Communication.Bovespa.Parametro.ParametroBolsa.ParametroBolsaResponse _response = new ParametroBolsaResponse();
                    _response = servico.ObterParametroBolsa();

                    retorno = _translatorDataContractToModel.ToParametroBolsa(_response);
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }

            return retorno;
		}
	}
}